/*
 * @(#)ListWorkflowAnalysisReportAction.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.workflow.web;

import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Colour;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.MessageResourcesFactory;
import com.dcivision.framework.SystemFunctionConstant;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.UserInfoFactory;
import com.dcivision.framework.Utility;
import com.dcivision.framework.web.AbstractListAction;
import com.dcivision.user.bean.UserGroup;
import com.dcivision.user.bean.UserRole;
import com.dcivision.user.dao.UserGroupDAObject;
import com.dcivision.user.dao.UserRoleDAObject;
import com.dcivision.workflow.bean.MtmWorkflowStepUserActor;
import com.dcivision.workflow.bean.WorkflowGroup;
import com.dcivision.workflow.bean.WorkflowRecord;
import com.dcivision.workflow.bean.WorkflowStage;
import com.dcivision.workflow.dao.WorkflowGroupDAObject;
import com.dcivision.workflow.dao.WorkflowRecordDAObject;
import com.dcivision.workflow.dao.WorkflowReportDAObject;
import com.dcivision.workflow.dao.WorkflowStageDAObject;

/**
 * <p>Class Name:       ListWorkflowAnalysisReportAction.java    </p>
 * <p>Description:      The list action class for ListWorkflowAnalysisReport.jsp</p>
 * @author           Dick Xie
 * @company          DCIVision Limited
 * @creation date    13/05/2005
 * @version          $Revision: 1.19 $
 */

public class ListWorkflowAnalysisReportAction extends AbstractListAction {

  public static final String REVISION = "$Revision: 1.19 $";
  private final String GENERATE_EXCEL = "G";

  /** Creates a new instance of ListWorkflowAnalysisReportAction */
  public ListWorkflowAnalysisReportAction() {
    super();
//    this.setListName("workflowTaskList");
//    this.setListFunctionName("getListPendingForUser");
  }

  public String getFunctionCode() {
    return (SystemFunctionConstant.WORKFLOW_REPORT);
  }

  public String getMajorDAOClassName() {
    return("com.dcivision.customize.workflow.dao.WorkflowReportDAObject");
  }

  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException {
    ListWorkflowMonitoringForm listWorkflowMonitoringForm = (ListWorkflowMonitoringForm)form;
     
    ActionForward forward = this.retrieveFunctionCode(request, response, mapping);
    if (forward!=null) {
      return forward;
    }
    
    String navMode = request.getParameter("navMode");
    WorkflowReportDAObject workflowReportDAObject = new WorkflowReportDAObject(this.getSessionContainer(request), this.getConnection(request));
    WorkflowGroupDAObject workflowGroupDAO = new WorkflowGroupDAObject(this.getSessionContainer(request), this.getConnection(request));
    WorkflowRecordDAObject  workflowRecordDAObject = new WorkflowRecordDAObject(this.getSessionContainer(request), this.getConnection(request));
    WorkflowStageDAObject workflowStageDAO = new WorkflowStageDAObject(this.getSessionContainer(request), this.getConnection(request));
    List workflowGroupList = workflowGroupDAO.getFullList();
    request.setAttribute("workflowGroupList", workflowGroupList);
    List workflowRecordList = new ArrayList();
    if (Utility.isEmpty(listWorkflowMonitoringForm.getWorkflowGroupID())) {
      workflowRecordList = workflowRecordDAObject.getFullList();
    } else {
      workflowRecordList = workflowRecordDAObject.getListByWorkflowGroupID(new Integer(listWorkflowMonitoringForm.getWorkflowGroupID()));
    }
    
    //Add by Samlin
    workflowRecordList=getWorkflowListForRelease( workflowRecordList);
    //End by Samlin
    
    request.setAttribute("workflowRecordList", workflowRecordList);

    if (!Utility.isEmpty(navMode) && GlobalConstant.NAV_MODE_LIST.equals(navMode) && !Utility.isEmpty(listWorkflowMonitoringForm.getWorkflowRecordID()) && !Utility.isEmpty(listWorkflowMonitoringForm.getDatePeriodFrom()) && !Utility.isEmpty(listWorkflowMonitoringForm.getDatePeriodTo())){
      // Part A
      int pendingWorkflowTrackNumberBefore = 0;
      int createdWorkflowTrackNumber = 0;
      int completedWorkflowTrackNumber = 0;
      int stoppedWorkflowTrackNumber = 0;
      int pendingWorkflowTrackNumberAfter = 0;
      if (!Utility.isEmpty(listWorkflowMonitoringForm.getDatePeriodFrom())) {
        pendingWorkflowTrackNumberBefore = workflowReportDAObject.getWorkflowTrackNumberBeforeThisTime(listWorkflowMonitoringForm);
      }
      //get  number of workflow Track  triggered during the specified period;
      createdWorkflowTrackNumber = workflowReportDAObject.getCreatedTrackNumber(listWorkflowMonitoringForm);
      //get number of workflow Track completed during the specified period; 
      completedWorkflowTrackNumber = workflowReportDAObject.getCompletedTrackNumber(listWorkflowMonitoringForm);
      stoppedWorkflowTrackNumber = workflowReportDAObject.getStoppedWorkflowTrackNumber(listWorkflowMonitoringForm);
      pendingWorkflowTrackNumberAfter = pendingWorkflowTrackNumberBefore + createdWorkflowTrackNumber - completedWorkflowTrackNumber - stoppedWorkflowTrackNumber;
      request.setAttribute("pendingWorkflowTrackNumberBefore" , new Integer(pendingWorkflowTrackNumberBefore));
      request.setAttribute("createdWorkflowTrackNumber" , new Integer(createdWorkflowTrackNumber));
      request.setAttribute("completedWorkflowTrackNumber" , new Integer(completedWorkflowTrackNumber));
      request.setAttribute("stoppedWorkflowTrackNumber" , new Integer(stoppedWorkflowTrackNumber));
      request.setAttribute("pendingWorkflowTrackNumberAfter" , new Integer(pendingWorkflowTrackNumberAfter));
      listWorkflowMonitoringForm.setNavMode(GlobalConstant.NAV_MODE_LIST);

      // Part B
      List workflowStageList = workflowStageDAO.getListByWorkflowRecordID(new Integer(listWorkflowMonitoringForm.getWorkflowRecordID()));
      request.setAttribute("workflowStageList" , workflowStageList);
      if (!Utility.isEmpty(workflowStageList)) {
        List workflowTaskExeTimeList = workflowReportDAObject.getWorkflowTrackListByWorkflowRecord(listWorkflowMonitoringForm);
        List formatWorkflowTaskList = new ArrayList();
        if (!Utility.isEmpty(workflowTaskExeTimeList)) {
          formatWorkflowTaskList.add(this.getMaxMinAvgValue(workflowTaskExeTimeList));
        }
        List workflowTaskExeTimeByOwnerList = workflowReportDAObject.getWorkflowTrackListByOwner(listWorkflowMonitoringForm);
        Map workflowOwnerMap = new HashMap();
        List workflowOwnerList = new ArrayList();
        List formatWorkflowTaskExeTimeList = new ArrayList();
        List formatWorkflowTaskExeTimeActionTakerList = new ArrayList();
        for (int i = 0; !Utility.isEmpty(workflowTaskExeTimeByOwnerList) && i < workflowTaskExeTimeByOwnerList.size(); i++) {
         String[] curValue = (String[])workflowTaskExeTimeByOwnerList.get(i);
          String curNameValue = this.getOwnerNameByActorIDAndActorType(new Integer(curValue[2]), curValue[4], request);
          if (!Utility.isEmpty(curNameValue) && !workflowOwnerMap.containsKey(curNameValue)) {
            workflowOwnerMap.put(curNameValue, new Integer(curValue[2])); 
            workflowOwnerList.add(curNameValue);
          }
        }
        for (int j = 0; !Utility.isEmpty(workflowStageList) && j < workflowStageList.size(); j++) {
          WorkflowStage workflowStage =(WorkflowStage) workflowStageList.get(j);
          for (int k = 0; !Utility.isEmpty(workflowOwnerList) && k < workflowOwnerList.size(); k++) {
          	boolean flag = true;
            Float maxValue = new Float(0); 
            Float minValue = new Float(0);
            Float avgValue = new Float(0);
            Float sunValue = new Float(0);
            int currentCount = 0;// count track total number
            for (int i = 0; !Utility.isEmpty(workflowTaskExeTimeByOwnerList) && i < workflowTaskExeTimeByOwnerList.size(); i++) {
              String[] curValue = (String[])workflowTaskExeTimeByOwnerList.get(i);
              String curNameValue = this.getOwnerNameByActorIDAndActorType(new Integer(curValue[2]), curValue[4], request);
              if (!Utility.isEmpty(curNameValue) && curValue[1].equals(workflowStage.getID().toString()) && curNameValue.equals((String)workflowOwnerList.get(k))){
              	currentCount++;
                Float currentValue = Float.valueOf(curValue[5]);
                if (currentValue.floatValue() > maxValue.floatValue()) {
                  maxValue = currentValue; 
                }
                if (currentValue.floatValue() < minValue.floatValue() || new Float(0).equals(minValue)) {
                  minValue = currentValue; 
                }
                if (flag) {//if record is frist;
                	sunValue = currentValue;
                	flag = false;
                } else {
                	sunValue = new Float(sunValue.floatValue() + currentValue.floatValue());
                }
              }
            }
            // get average value ;
            if (sunValue.floatValue() > 0) {
            	avgValue = new Float(sunValue.floatValue()/currentCount);
            }
            String values[] = new String[]{workflowStage.getStageName(),
                                           String.valueOf(workflowOwnerList.get(k)),
                                           String.valueOf(minValue),
                                           String.valueOf(maxValue),
                                           String.valueOf(avgValue)}; 
            formatWorkflowTaskExeTimeList.add(values);   
          } 
        }
        List workflowTaskExeTimeByActionTakerList = workflowReportDAObject.getWorkflowTrackListByActionTaker(listWorkflowMonitoringForm);
        Map workflowActionTakerMap = new HashMap();
        List workflowActionTakerList = new ArrayList();
        for (int i = 0; !Utility.isEmpty(workflowTaskExeTimeByActionTakerList) && i < workflowTaskExeTimeByActionTakerList.size(); i++) {
          String[] curValue = (String[])workflowTaskExeTimeByActionTakerList.get(i);
          if (!workflowActionTakerMap.containsKey(curValue[3])) {
            workflowActionTakerMap.put(curValue[3], null); 
            workflowActionTakerList.add(curValue[3]);
          }
        }
        for (int j = 0; !Utility.isEmpty(workflowStageList) && j < workflowStageList.size(); j++) {
          WorkflowStage workflowStage =(WorkflowStage) workflowStageList.get(j);
          for (int k = 0; !Utility.isEmpty(workflowActionTakerList) && k < workflowActionTakerList.size(); k++) {
          	boolean flag = true;
            Float maxValue = new Float(0); 
            Float minValue = new Float(0);
            Float avgValue = new Float(0);
            Float sunValue = new Float(0);
            int currentCount = 0;// count track total number
            for (int i = 0; !Utility.isEmpty(workflowTaskExeTimeByActionTakerList) && i < workflowTaskExeTimeByActionTakerList.size(); i++) {
              String[] curValue = (String[])workflowTaskExeTimeByActionTakerList.get(i);
              if (curValue[1].equals(workflowStage.getID().toString()) && curValue[3].equals((String)workflowActionTakerList.get(k))){
              	currentCount++;
              	Float currentValue = Float.valueOf(curValue[4]);
                if (currentValue.floatValue() > maxValue.floatValue()) {
                  maxValue = currentValue; 
                }
                if (currentValue.floatValue() < minValue.floatValue() || new Float(0).equals(minValue)) {
                  minValue = currentValue; 
                }
                if (flag) {//if record is frist;
                	sunValue = currentValue;
                	flag = false;
                } else {
                  sunValue = new Float(sunValue.floatValue() + currentValue.floatValue());
                }
              }
            }// get average value ;
            if (sunValue.floatValue() > 0) {
            	avgValue = new Float(sunValue.floatValue()/currentCount);
            }
            String values[] = new String[]{workflowStage.getStageName(),
                                          String.valueOf(workflowActionTakerList.get(k)),
                                           String.valueOf(minValue),
                                           String.valueOf(maxValue),
                                           String.valueOf(avgValue)                               
            }; 
            formatWorkflowTaskExeTimeActionTakerList.add(values);   
          } 
        }
        request.setAttribute("WorkflowTaskExeTimeInfoList", (formatWorkflowTaskList));
        request.setAttribute("WorkflowTaskExeTimeByOwnerList", (formatWorkflowTaskExeTimeList));
        request.setAttribute("WorkflowTaskExeTimeByActionTakerList", (formatWorkflowTaskExeTimeActionTakerList));
      }
      //  Part C

      List completeWorkflowTrackList = workflowReportDAObject.getCompletedTrackList(listWorkflowMonitoringForm);
      long completeOnTimeTrackNumber = 0;
      long completeDelayTrackNumber = 0;
      long MaxcompleteOnTimeDay = 0;
      long MincompleteOnTimeDay = 0;
      long AvgcompleteOnTimeDay = 0;
      long MaxcompleteDelayDay = 0;
      long MincompleteDelayDay = 0;
      long AvgcompleteDelayDay = 0;
      long sumCompleteDay = 0;
      long indexOnTime = 0;
      long sumDelayDay = 0;
      long indexDelay = 0;

      if (!Utility.isEmpty(listWorkflowMonitoringForm.getWorkflowRecordID())) {
        long workflowRecordDurationTime =(long)((workflowReportDAObject.getWorkflowRecordDuratoin(new Integer(listWorkflowMonitoringForm.getWorkflowRecordID()))) * 60.0F * 60.0F * 24.0F);
        for (int i = 0; i < completeWorkflowTrackList.size(); i++) {
          log.debug("this workflowRecordDurationTime is ::::" + workflowRecordDurationTime);
          String[] currentExeTime = (String[])completeWorkflowTrackList.get(i);
          long currentExeTimeValue = new Long(currentExeTime[1]).longValue();
          log.debug("the currentExeTime for Track ::::" +  currentExeTimeValue);
          if (workflowRecordDurationTime > currentExeTimeValue) {
            long currentOnTimeDay =  workflowRecordDurationTime-currentExeTimeValue;
            if (MaxcompleteOnTimeDay == 0) {
             MaxcompleteOnTimeDay = currentOnTimeDay;
            } else if (MaxcompleteOnTimeDay < currentOnTimeDay) {
              MaxcompleteOnTimeDay = currentOnTimeDay;
            }
            if (MincompleteOnTimeDay == 0) {
              MincompleteOnTimeDay = currentOnTimeDay;
            } else if (MincompleteOnTimeDay > currentOnTimeDay) {
              MincompleteOnTimeDay = currentOnTimeDay;
            }
            sumCompleteDay += currentOnTimeDay;
            indexOnTime++;
            completeOnTimeTrackNumber++;
          } else {
            long currentDelayDay = currentExeTimeValue-workflowRecordDurationTime;
            if (MaxcompleteDelayDay == 0) {
              MaxcompleteDelayDay = currentDelayDay;
            } else if (MaxcompleteDelayDay < currentDelayDay) {
              MaxcompleteDelayDay = currentDelayDay;
            }
            if (MincompleteDelayDay == 0) {
              MincompleteDelayDay = currentDelayDay;
            } else if (MincompleteDelayDay > currentDelayDay) {
              MincompleteDelayDay = currentDelayDay;
            }
            sumDelayDay += currentDelayDay;
            indexDelay++;
            completeDelayTrackNumber++;
          }
        }
      }
      if (indexOnTime != 0) {
        AvgcompleteOnTimeDay = sumCompleteDay/indexOnTime;
      }
      if (indexDelay != 0) {
        AvgcompleteDelayDay = sumDelayDay/indexDelay;
      }
      request.setAttribute("completeOnTimeTrackNumber", new Long(completeOnTimeTrackNumber));
      request.setAttribute("completeDelayTrackNumber", new Long(completeDelayTrackNumber));
      request.setAttribute("MaxcompleteOnTimeDay", new Long(MaxcompleteOnTimeDay));
      request.setAttribute("MincompleteOnTimeDay", new Long(MincompleteOnTimeDay));
      request.setAttribute("MaxcompleteDelayDay", new Long(MaxcompleteDelayDay));
      request.setAttribute("MincompleteDelayDay", new Long(MincompleteDelayDay));
      request.setAttribute("AvgcompleteOnTimeDay", new Long(AvgcompleteOnTimeDay));
      request.setAttribute("AvgcompleteDelayDay", new Long(AvgcompleteDelayDay));
    }
    String generateExcel = request.getParameter("generateExcel");
    String generateAllExcel = request.getParameter("generateAllExcel");
    if(!Utility.isEmpty(generateExcel) && GENERATE_EXCEL.equals(generateExcel)){
    	Locale locale = this.getSessionContainer(request).getSessionLocale();
      //String filePath = SystemParameterFactory.getSystemParameter(SystemParameterConstant.WORKFLOW_ATTACHMENT_PHYSICAL_PATH);
      String fileName = MessageFormat.format(MessageResourcesFactory.getMessage(locale,"workflow.report.excel.filename"), new Object[]{new java.util.Date()});
      generateExcelFile(listWorkflowMonitoringForm,fileName,locale,request,response);
      return null;
      //  return mapping.findForward(GENERATE_EXCEL);
    }
    return mapping.findForward(GlobalConstant.NAV_MODE_LIST);
//  return super.execute ( mapping, form, request, response );
  }

	private List getWorkflowListForRelease(List workflowRecordList) {
		List list = new ArrayList();
		for (Iterator iter = workflowRecordList.iterator(); iter.hasNext();) {
			WorkflowRecord element = (WorkflowRecord) iter.next();
			if (GlobalConstant.RECORD_RELEASED.equals(element.getStatus())) {
				list.add(element);
			}
		}
		return list;
	}

	/*
  private List getMinMaxAvgTimeForWorkflowRecord(List sourceTimeInfoList)throws ApplicationException {
    List returnInfoList = new ArrayList();
    long minExeTime = 0;
    long maxExeTime = 0;
    long sumExeTime = 0;
    int trackNumber = 0;
    if (!Utility.isEmpty(sourceTimeInfoList)) {
      for (int i = 0; i < sourceTimeInfoList.size(); i++) {
        WorkflowRecordExeTime currentWorkflowTaskExeTime = (WorkflowRecordExeTime)sourceTimeInfoList.get(i);
        long currentExeTime = getExeTime(currentWorkflowTaskExeTime.getStartDate(), currentWorkflowTaskExeTime.getEndDate());
        if (currentExeTime != -1) {
          if (currentExeTime < minExeTime) {
            minExeTime = currentExeTime;
          }
          if (currentExeTime > maxExeTime) {
            maxExeTime = currentExeTime;
          }
          sumExeTime += currentExeTime;
          trackNumber++;
        }
      }
      returnInfoList.add(new Long(minExeTime));
      returnInfoList.add(new Long(maxExeTime));
      returnInfoList.add(new Long(sumExeTime/trackNumber));
    }
    return returnInfoList;
  }

  private List getMinMaxAvgTimeForOwner(List sourceTimeInfoList)throws ApplicationException {
    List returnInfoList = new ArrayList();
    long minExeTime = 0;
    long maxExeTime = 0;
    long sumExeTime = 0;
    int trackNumber = 0;
    if (!Utility.isEmpty(sourceTimeInfoList)) {
      for (int i = 0; i < sourceTimeInfoList.size(); i++) {
        WorkflowStepExeTimeByOwner curWorkflowStepExeTimeByOwner = (WorkflowStepExeTimeByOwner)sourceTimeInfoList.get(i);
        long currentExeTime = getExeTime(curWorkflowStepExeTimeByOwner.getStartDate(), curWorkflowStepExeTimeByOwner.getEndDate());
        if (currentExeTime != -1) {
          if (i == 0) {
            minExeTime = currentExeTime;
            maxExeTime = currentExeTime;
          } else {
            if (currentExeTime < minExeTime) {
              minExeTime = currentExeTime;
            }
            if (currentExeTime > maxExeTime) {
              maxExeTime = currentExeTime;
            }
          }
          sumExeTime += currentExeTime;
          trackNumber++;
        }
      }
      returnInfoList.add(new Long(minExeTime));
      returnInfoList.add(new Long(maxExeTime));
      returnInfoList.add(new Long(sumExeTime/trackNumber));
    }
    return returnInfoList;
  }

  private long getExeTime(Timestamp startDate, Timestamp endDate) {
    long startDateTime = startDate.getTime();
    long endDateTime = endDate.getTime();
    if (startDateTime <= endDateTime) {
      return endDateTime-startDateTime;
    } else {
      return -1;
    }
  }

  private Integer getWorkflowRecordIDByTrackID(Integer trackID, HttpServletRequest request)throws ApplicationException {
    Integer workflowRecordID = null;
    WorkflowProgressDAObject workflowProgressDAO = new WorkflowProgressDAObject(this.getSessionContainer(request), this.getConnection(request));
    WorkflowStepDAObject workflowStepDAO =new WorkflowStepDAObject(this.getSessionContainer(request), this.getConnection(request));
    List workflowProgressList = workflowProgressDAO.getListByTrackID(trackID);
    if (!Utility.isEmpty(workflowProgressList)) {
      WorkflowStep workflowStep = (WorkflowStep)workflowStepDAO.getObjectByID(((WorkflowProgress)(workflowProgressList.get(0))).getWorkflowStepID());
      workflowRecordID = workflowStep.getWorkflowRecordID();
    }
    return workflowRecordID;
  }
*/
  private void generateExcelFile(
  		ListWorkflowMonitoringForm listWorkflowMonitoringForm,
			String fileName,
			Locale locale,
			HttpServletRequest request,
			HttpServletResponse response)
  throws ApplicationException {
  	try{
  		response.addHeader("Content-Transfer-Encoding", "base64");
  		response.addHeader("Content-Disposition", "attachment; filename=" + fileName + "\"");
  		
  	 WorkflowGroupDAObject groupDAO = new WorkflowGroupDAObject(this.getSessionContainer(request),this.getConnection(request));
  	 WorkflowRecordDAObject recordDAO = new WorkflowRecordDAObject(this.getSessionContainer(request), this.getConnection(request));
  		//Set these Cell Format
  		WritableFont titleFont = new WritableFont(WritableFont.TIMES, 14, WritableFont.BOLD);
  		WritableFont headerFont = new WritableFont(WritableFont.TIMES, 9, WritableFont.BOLD);
  		WritableFont bodyFont = new WritableFont(WritableFont.TIMES, 9, WritableFont.BOLD);
  		WritableFont footerFont = new WritableFont(WritableFont.TIMES, 9, WritableFont.BOLD);
  		
  		WritableCellFormat titleCellFormat = new WritableCellFormat(titleFont);
  		WritableCellFormat headerCellFormat = new WritableCellFormat(headerFont);
  		WritableCellFormat bodyCellFormat = new WritableCellFormat(bodyFont);
  		WritableCellFormat footerCellFormat = new WritableCellFormat(footerFont);
  		WritableCellFormat remarkCellFormat = new WritableCellFormat(bodyFont);
  		WritableCellFormat seperatorCellFormatRight = new WritableCellFormat(bodyFont);
  		WritableCellFormat seperatorCellFormatLeft = new WritableCellFormat(bodyFont);
  		WritableCellFormat onLoanCellFormat = new WritableCellFormat(bodyFont);
  		
  		headerCellFormat.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
  		bodyCellFormat.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
  		//seperatorCellFormatRight.setBorder(jxl.format.Border.RIGHT,jxl.format.BorderLineStyle.THIN);
  		//seperatorCellFormatRight.setBorder(jxl.format.Border.BOTTOM,jxl.format.BorderLineStyle.THIN);
  		//seperatorCellFormatRight.setBorder(jxl.format.Border.TOP,jxl.format.BorderLineStyle.THIN);
  		seperatorCellFormatLeft.setBorder(jxl.format.Border.LEFT,jxl.format.BorderLineStyle.THIN);
  		seperatorCellFormatLeft.setBorder(jxl.format.Border.BOTTOM,jxl.format.BorderLineStyle.THIN);
  		seperatorCellFormatLeft.setBorder(jxl.format.Border.TOP,jxl.format.BorderLineStyle.THIN);
  		
  		headerCellFormat.setAlignment(Alignment.CENTRE);
  		bodyCellFormat.setAlignment(Alignment.CENTRE);
  		headerCellFormat.setVerticalAlignment(VerticalAlignment.TOP);
  		bodyCellFormat.setVerticalAlignment(VerticalAlignment.TOP);
  		headerCellFormat.setBackground(Colour.GRAY_25);
  		
  		seperatorCellFormatLeft.setBackground(Colour.GRAY_25);
  		//seperatorCellFormatRight.setBackground(Colour.GRAY_25);
  		onLoanCellFormat.setBackground(Colour.BLACK);
  		headerCellFormat.setWrap(true);
  		bodyCellFormat.setWrap(true);
  		
  		
  		ServletOutputStream sos = response.getOutputStream();
  		WritableWorkbook book = Workbook.createWorkbook(sos);
  		WritableSheet sheet = book.createSheet(MessageResourcesFactory.getMessage(locale, "workflow.report.excel.sheetname"),0);
  		//          SheetSettings ss = ws.getSettings();
  		//          ss.setBottomMargin(0.5);
  		//          ss.setLeftMargin(0.5);
  		//          ss.setRightMargin(0.5);
  		//          ss.setTopMargin(0.5);
  		//          
  		//sheet.setFooter("","","page &P of &N");
  		sheet.setColumnView(0,25);//
  		sheet.setColumnView(1,14);//
  		sheet.setColumnView(2,8);//
  		sheet.setColumnView(3,25);//
  		sheet.setColumnView(4,25);//
  		sheet.setColumnView(5,25);//
  		
  		List workflowTaskExeTimeInfoList = (List)request.getAttribute("WorkflowTaskExeTimeInfoList");
      List workflowTaskExeTimeByOwnerList = (List)request.getAttribute("WorkflowTaskExeTimeByOwnerList");
      List workflowTaskExeTimeByActionTakerList = (List)request.getAttribute("WorkflowTaskExeTimeByActionTakerList");
  		Label label = null;
  		int row = 16;
  		
  		//set the title
  		label = new Label(3,1,MessageResourcesFactory.getMessage(locale, "export.report.eip.analysis.list") );//
  		label.setCellFormat(titleCellFormat);
  		sheet.addCell(label);
  		
  		//set the generation time
  		label = new Label(0,3,MessageResourcesFactory.getMessage(locale, "common.report_generation_time") );//
  		label.setCellFormat(seperatorCellFormatRight);
  		sheet.addCell(label);
  		
  		label = new Label(2,3,TextUtility.formatTimestamp(Utility.getCurrentTimestamp()) );
  		//label.setCellFormat(bodyCellFormat);
  		sheet.addCell(label);
  		
  		//set the generated by
  		label = new Label(0,4,MessageResourcesFactory.getMessage(locale, "common.report_generated_by") );//
  		label.setCellFormat(seperatorCellFormatRight);
  		sheet.addCell(label);
  		
  		label = new Label(2,4,UserInfoFactory.getUserFullName(this.getSessionContainer(request).getUserRecordID()) );
  		//label.setCellFormat(bodyCellFormat);
  		sheet.addCell(label);
  		
  		label = new Label(0,5,MessageResourcesFactory.getMessage(locale, "workflow.columnheader.group_name") );//
  		label.setCellFormat(seperatorCellFormatRight);
  		sheet.addCell(label);
  		if (!Utility.isEmpty(listWorkflowMonitoringForm.getWorkflowGroupID())) {
  		 WorkflowGroup workflowGroup = (WorkflowGroup)groupDAO.getObjectByID(new Integer(listWorkflowMonitoringForm.getWorkflowGroupID()));
  		 label = new Label(2,5,workflowGroup.getGroupName());
   		//label.setCellFormat(bodyCellFormat);
   		 sheet.addCell(label);
  		}
  		
  		
  		label = new Label(0,6,MessageResourcesFactory.getMessage(locale, "workflow.monitor.track.workflow_record") );//
  		label.setCellFormat(seperatorCellFormatRight);
  		sheet.addCell(label);
  		
  		if (!Utility.isEmpty(listWorkflowMonitoringForm.getWorkflowRecordID())) {
  			WorkflowRecord workflowRecord = (WorkflowRecord)recordDAO.getObjectByID(new Integer(listWorkflowMonitoringForm.getWorkflowRecordID()));
   		 label = new Label(2,6,workflowRecord.getWorkflowCode() + "[" + workflowRecord.getWorkflowVersion() + "]");
    		//label.setCellFormat(bodyCellFormat);
    		 sheet.addCell(label);
   		}
  		
  		label = new Label(0,7,MessageResourcesFactory.getMessage(locale, "workflow.report.date_range") );//
  		label.setCellFormat(seperatorCellFormatRight);
  		sheet.addCell(label);
  		
  		label = new Label(2,7,listWorkflowMonitoringForm.getDatePeriodFrom() );
  		//label.setCellFormat(bodyCellFormat);
  		sheet.addCell(label);
  		sheet.mergeCells(2, 7, 3, 7);
  		
  		label = new Label(4,7,listWorkflowMonitoringForm.getDatePeriodTo() );
  		//label.setCellFormat(bodyCellFormat);
  		sheet.addCell(label);
  		
  		label = new Label(0,8,MessageResourcesFactory.getMessage(locale, "workflow.report.count") );//
  		label.setCellFormat(seperatorCellFormatRight);
  		sheet.addCell(label);
  		
  		label = new Label(0,9,MessageResourcesFactory.getMessage(locale, "workflow.report.pending_before"));//
  		label.setCellFormat(headerCellFormat);
  		sheet.addCell(label);
  		sheet.mergeCells(0, 9, 4, 9);
  		
  		label = new Label(5,9,((Integer)request.getAttribute("pendingWorkflowTrackNumberBefore")).toString());//
  		label.setCellFormat(headerCellFormat);
  		sheet.addCell(label);
  		
  		label = new Label(0,10,MessageResourcesFactory.getMessage(locale, "workflow.report.created"));//
  		label.setCellFormat(headerCellFormat);
  		sheet.addCell(label);
  		sheet.mergeCells(0, 10, 4, 10);
  		
  		label = new Label(5,10,((Integer)request.getAttribute("createdWorkflowTrackNumber")).toString());//
  		label.setCellFormat(headerCellFormat);
  		sheet.addCell(label);
  		
  		label = new Label(0,11,MessageResourcesFactory.getMessage(locale, "workflow.report.completed"));//
  		label.setCellFormat(headerCellFormat);
  		sheet.addCell(label);
  		sheet.mergeCells(0, 11, 4,11);
  		
  		label = new Label(5,11,((Integer)request.getAttribute("completedWorkflowTrackNumber")).toString());//
  		label.setCellFormat(headerCellFormat);
  		sheet.addCell(label);
  		
  		label = new Label(0,12,MessageResourcesFactory.getMessage(locale, "workflow.report.stopped"));//
  		label.setCellFormat(headerCellFormat);
  		sheet.addCell(label);
  		sheet.mergeCells(0, 12, 4, 12);
  		
  		label = new Label(5,12,((Integer)request.getAttribute("stoppedWorkflowTrackNumber")).toString());//
  		label.setCellFormat(headerCellFormat);
  		sheet.addCell(label);
  		
  		label = new Label(0,13,MessageResourcesFactory.getMessage(locale, "workflow.report.pending_after"));//
  		label.setCellFormat(headerCellFormat);
  		sheet.addCell(label);
  		sheet.mergeCells(0, 13, 4, 13);
  		
  		label = new Label(5,13,((Integer)request.getAttribute("pendingWorkflowTrackNumberAfter")).toString());//
  		label.setCellFormat(headerCellFormat);
  		sheet.addCell(label);
  		
  		if (Utility.isEmpty((List)request.getAttribute("workflowStageList")) && ((Integer)request.getAttribute("completedWorkflowTrackNumber")).intValue() > 0) {
        row++;
        label = new Label(0,row,MessageResourcesFactory.getMessage(locale, "workflow.report.stage_set_is_required") );//
        label.setCellFormat(seperatorCellFormatRight);
        sheet.addCell(label); 
        sheet.mergeCells(0,row,5,row);
      } else if(!Utility.isEmpty(workflowTaskExeTimeInfoList)){
  			label = new Label(0,14,MessageResourcesFactory.getMessage(locale, "workflow.report.used_time") );// Time
    		label.setCellFormat(seperatorCellFormatRight);
    		sheet.addCell(label);
    		sheet.mergeCells(0, 14, 4, 14);
  			
  		label = new Label(0,row,MessageResourcesFactory.getMessage(locale, "workflow.report.min_used"));//
  		label.setCellFormat(headerCellFormat);
  		sheet.addCell(label);
  		sheet.mergeCells(0, row, 1, row);
  		
  		label = new Label(2,row,MessageResourcesFactory.getMessage(locale, "workflow.report.max_used"));//
  		label.setCellFormat(headerCellFormat);
  		sheet.addCell(label);
  		sheet.mergeCells(2, row, 3, row);
  		
  		label = new Label(4,row,MessageResourcesFactory.getMessage(locale, "workflow.report.avg_used"));//
  		label.setCellFormat(headerCellFormat);
  		sheet.addCell(label);
  		sheet.mergeCells(4, row, 5, row);
  	
  		row++;
  		
     
     	String values[] = (String[])workflowTaskExeTimeInfoList.get(0);
  		 label = new Label(0,row, this.formatDuration(values[0]));//Min used
  		 //label.setCellFormat(headerCellFormat);
  		 sheet.addCell(label);
  		 sheet.mergeCells(0, row, 1, row);
  		 label = new Label(2,row, this.formatDuration(values[1]));//Max used
  		 //label.setCellFormat(headerCellFormat);
  		 sheet.addCell(label);
  		 sheet.mergeCells(2, row, 3, row);
  		
  		 label = new Label(4,row, this.formatDuration(values[2]));//
  		 //label.setCellFormat(headerCellFormat);
  		 sheet.addCell(label);
  		 sheet.mergeCells(4, row, 5, row);
     
     row = row + 2;
     label = new Label(0,row,MessageResourcesFactory.getMessage(locale, "workflow.report.stage"));//
  		label.setCellFormat(headerCellFormat);
  		sheet.addCell(label);
  		
  		label = new Label(1,row,MessageResourcesFactory.getMessage(locale, "workflow.report.role"));//
   		label.setCellFormat(headerCellFormat);
   		sheet.addCell(label);
   		sheet.mergeCells(1, row, 2, row);
   		
     label = new Label(3,row,MessageResourcesFactory.getMessage(locale, "workflow.report.min_used"));//
 		label.setCellFormat(headerCellFormat);
 		sheet.addCell(label);
 		
 		label = new Label(4,row,MessageResourcesFactory.getMessage(locale, "workflow.report.max_used"));//
 		label.setCellFormat(headerCellFormat);
 		sheet.addCell(label);
 		
 		label = new Label(5,row,MessageResourcesFactory.getMessage(locale, "workflow.report.avg_used"));//
 		label.setCellFormat(headerCellFormat);
 		sheet.addCell(label);
 		
 		List stageList = new ArrayList();
    Map stageMap = new TreeMap();
    for(int i=0;i<workflowTaskExeTimeByOwnerList.size();i++){
      values = (String[])workflowTaskExeTimeByOwnerList.get(i);
      List valueList = new ArrayList();
      if(stageMap.containsKey(values[0])){
        valueList = (List)stageMap.get(values[0]);
      }else{
        stageList.add ( values[0] );
      }
      valueList.add(values);
      stageMap.put(values[0], valueList);
    }
    Iterator stageItr = stageList.iterator();
    for(int i=0;stageItr.hasNext();i++){
      String stageName = (String)stageItr.next();
      List valueList = (List)stageMap.get(stageName);
      String value0[] = (String[])valueList.get(0);
    row++;
    label = new Label(0,row,stageName);//
		sheet.addCell(label);
		sheet.mergeCells(0, row, 0, row+valueList.size()-1);
		
		label = new Label(1,row,value0[1]);//
 		sheet.addCell(label);
 		sheet.mergeCells(1, row, 2, row);
 		
   label = new Label(3,row, this.formatDuration(value0[2]));//
		sheet.addCell(label);
		
		label = new Label(4,row,this.formatDuration(value0[3]));//
		sheet.addCell(label);
		
		label = new Label(5,row, this.formatDuration(value0[4]) );//
		sheet.addCell(label);
    row++;
    for(int j=1;j<valueList.size();j++){
    	values = (String[])valueList.get(j);
    	
    	label = new Label(1,row,values[1]);//
   		sheet.addCell(label);
   		
     label = new Label(3,row,this.formatDuration(values[2]) );//
  		sheet.addCell(label);
  		
  		label = new Label(4,row, this.formatDuration(values[3]) );//
  		sheet.addCell(label);
  		
  		label = new Label(5,row, this.formatDuration(values[4]) );//
  		sheet.addCell(label);
      row++;
    	
      }
    
    }
    row++;
    label = new Label(0,row,MessageResourcesFactory.getMessage(locale, "workflow.report.stage"));//
 		label.setCellFormat(headerCellFormat);
 		sheet.addCell(label);
 		
 		label = new Label(1,row,MessageResourcesFactory.getMessage(locale, "workflow.report.action_taker"));//
  		label.setCellFormat(headerCellFormat);
  		sheet.addCell(label);
  		sheet.mergeCells(1, row, 2, row);
  		
    label = new Label(3,row,MessageResourcesFactory.getMessage(locale, "workflow.report.min_used"));//
		label.setCellFormat(headerCellFormat);
		sheet.addCell(label);
		
		label = new Label(4,row,MessageResourcesFactory.getMessage(locale, "workflow.report.max_used"));//
		label.setCellFormat(headerCellFormat);
		sheet.addCell(label);
		
		label = new Label(5,row,MessageResourcesFactory.getMessage(locale, "workflow.report.avg_used"));//
		label.setCellFormat(headerCellFormat);
		sheet.addCell(label);
		
		stageList = new ArrayList();
    stageMap = new TreeMap();
    for(int i=0;i<workflowTaskExeTimeByActionTakerList.size();i++){
      values = (String[])workflowTaskExeTimeByActionTakerList.get(i);
      List valueList = new ArrayList();
      if(stageMap.containsKey(values[0])){
        valueList = (List)stageMap.get(values[0]);
      }else{
        stageList.add ( values[0] );
      }
      valueList.add(values);
      stageMap.put(values[0], valueList);
    }
    stageItr = stageList.iterator();
    for(int i=0;stageItr.hasNext();i++){
      String stageName = (String)stageItr.next();
      List valueList = (List)stageMap.get(stageName);
      String value0[] = (String[])valueList.get(0);
      row++;
      label = new Label(0,row,stageName);//
  		sheet.addCell(label);
  		sheet.mergeCells(0, row, 0, row+valueList.size()-1);
  		
  		label = new Label(1,row,value0[1]);//
   		sheet.addCell(label);
   		
     label = new Label(3,row, this.formatDuration(value0[2]));//
  		sheet.addCell(label);
  		
  		label = new Label(4,row, this.formatDuration(value0[3]));//
  		sheet.addCell(label);
  		
  		label = new Label(5,row,this.formatDuration(value0[4]));//
  		sheet.addCell(label);
      row++;
      for(int j=1;j<valueList.size();j++){
       values = (String[])valueList.get(j);
      	
      	label = new Label(1,row,values[1]);//
     		sheet.addCell(label);
     		
       label = new Label(3,row, this.formatDuration(values[2]));//
    		sheet.addCell(label);
    		
    		label = new Label(4,row, this.formatDuration(values[3]));//
    		sheet.addCell(label);
    		
    		label = new Label(5,row, this.formatDuration(values[4]));//
    		sheet.addCell(label);
        row++;
  
      }
    }
    Long  completeOnTimeTrackNumber = (Long)request.getAttribute("completeOnTimeTrackNumber");
    Long  completeDelayTrackNumber =  (Long)request.getAttribute("completeDelayTrackNumber");
    Long  MaxcompleteOnTimeDay =  (Long)request.getAttribute("MaxcompleteOnTimeDay");
    Long  MincompleteOnTimeDay =  (Long)request.getAttribute("MincompleteOnTimeDay");
    Long  MaxcompleteDelayDay =  (Long)request.getAttribute("MaxcompleteDelayDay");
    Long  MincompleteDelayDay =  (Long)request.getAttribute("MincompleteDelayDay");
    Long  AvgcompleteOnTimeDay =  (Long)request.getAttribute("AvgcompleteOnTimeDay");
    Long  AvgcompleteDelayDay =  (Long)request.getAttribute("AvgcompleteDelayDay");
    row++;
    label = new Label(0,row,MessageResourcesFactory.getMessage(locale, "workflow.report.compare") );// 
		label.setCellFormat(seperatorCellFormatRight);
		sheet.addCell(label);
		row++;
    label = new Label(0,row,MessageResourcesFactory.getMessage(locale, "workflow.report.complete_before_after"));//
 		label.setCellFormat(headerCellFormat);
 		sheet.addCell(label);
 		
 		label = new Label(1,row,MessageResourcesFactory.getMessage(locale, "workflow.report.total"));//
    label.setCellFormat(headerCellFormat);
  	sheet.addCell(label);
  		
  	label = new Label(2,row,MessageResourcesFactory.getMessage(locale, "workflow.report.percentage"));//
  	label.setCellFormat(headerCellFormat);
  	sheet.addCell(label);
  		
    label = new Label(3,row,MessageResourcesFactory.getMessage(locale, "workflow.report.min_days"));//
		label.setCellFormat(headerCellFormat);
		sheet.addCell(label);
		
		label = new Label(4,row,MessageResourcesFactory.getMessage(locale, "workflow.report.max_days"));//
		label.setCellFormat(headerCellFormat);
		sheet.addCell(label);
		
		label = new Label(5,row,MessageResourcesFactory.getMessage(locale, "workflow.report.avg_days"));//
		label.setCellFormat(headerCellFormat);
		sheet.addCell(label);
		
		row++;
    label = new Label(0,row,MessageResourcesFactory.getMessage(locale, "workflow.report.complete_before"));//	
 		sheet.addCell(label);
 		
 		label = new Label(1,row,completeOnTimeTrackNumber.toString());//Priority
  	sheet.addCell(label);
  		
  	label = new Label(2,row,(float)completeOnTimeTrackNumber.intValue()/(completeOnTimeTrackNumber.intValue()+completeDelayTrackNumber.intValue())*100 +"%");//Priorit
  	sheet.addCell(label);
  		
    label = new Label(3,row,MincompleteOnTimeDay.intValue()==0? "-":formatDuration(MincompleteOnTimeDay.toString()));//Min complete on time days
		sheet.addCell(label);
		
		label = new Label(4,row,MaxcompleteOnTimeDay.intValue()==0? "-":formatDuration(MaxcompleteOnTimeDay.toString()));//Max complete on time days
		sheet.addCell(label);
		
		label = new Label(5,row,AvgcompleteOnTimeDay.intValue()==0? "-":formatDuration(AvgcompleteOnTimeDay.toString()));//avg complete on time days
		sheet.addCell(label);
		row++;
    label = new Label(0,row,MessageResourcesFactory.getMessage(locale, "workflow.report.complete_after"));//complete after	
 		sheet.addCell(label);
 		
 		label = new Label(1,row,completeDelayTrackNumber.toString());//number
  	sheet.addCell(label);
  		
  	label = new Label(2,row,(float)completeDelayTrackNumber.intValue()/(completeOnTimeTrackNumber.intValue()+completeDelayTrackNumber.intValue())*100 +"%");//complete delay %
  	sheet.addCell(label);
  		
    label = new Label(3,row,MincompleteDelayDay.intValue()==0? "-":formatDuration(MincompleteDelayDay.toString()));//Min complete dalay day
		sheet.addCell(label);
		
		label = new Label(4,row,MaxcompleteDelayDay.intValue()==0? "-":formatDuration(MaxcompleteDelayDay.toString()));//Max complete dalay day
		sheet.addCell(label);
		
		label = new Label(5,row,AvgcompleteDelayDay.intValue()==0? "-":formatDuration(AvgcompleteDelayDay.toString()));//avg complete dalay day
		sheet.addCell(label);
  } else {
  	row++;
  	label = new Label(0,row,MessageResourcesFactory.getMessage(locale, "workflow.report.no_completed_track") );//
		label.setCellFormat(seperatorCellFormatRight);
		sheet.addCell(label);	
		sheet.mergeCells(0,row,5,row);
  }
  		book.write();
  		book.close();
  	} catch (IOException e) {
  		throw new ApplicationException(e);
  	} catch (WriteException we){
  		throw new ApplicationException(we);
  	}
  	
  }
  
  public String formatDuration ( long duration ){
    long LONG_DAYS = 1000*60*60*24;
    long LONG_HOURS = 1000*60*60;
    long LONG_MINUTES = 1000*60;
    long LONG_SECONDS= 1000;
    long totalDays = duration/LONG_DAYS;
    long totalHours = (duration-(totalDays*LONG_DAYS))/LONG_HOURS;
    long totalMins = (duration-(totalDays*LONG_DAYS)-(totalHours*LONG_HOURS))/LONG_MINUTES;
    long totalSecs = (duration - (totalDays*LONG_DAYS)-(totalHours*LONG_HOURS)-(totalMins*LONG_MINUTES))/LONG_SECONDS;
    return totalDays+"d "+totalHours+"h "+totalMins+"m "+totalSecs+"s";
//    return duration/1000+"s";
  }
  
  private String formatDuration(String duration){
    return formatDuration ( Float.valueOf(duration).longValue()*1000 );
  }
  
  private String[] getMaxMinAvgValue(List sourceList) {
    Float maxValue = Float.valueOf((String)sourceList.get(0)); 
    Float minValue = Float.valueOf((String)sourceList.get(0));
    Float sunValue = Float.valueOf((String)sourceList.get(0));
    Float avgValue = new Float(0);
    for (int i = 1; !Utility.isEmpty(sourceList) && i < sourceList.size(); i++) {
      Float currentValue = Float.valueOf((String)sourceList.get(i));
      if (currentValue.floatValue() > maxValue.floatValue()) {
        maxValue = currentValue; 
      }
      if (currentValue.floatValue() < minValue.floatValue()) {
        minValue = currentValue; 
      }
      sunValue = new Float(sunValue.floatValue() + currentValue.floatValue());
    }
    if (sunValue.floatValue() > 0) {
    	avgValue = new Float(sunValue.floatValue()/sourceList.size());
    }
     String values[] = new String[]{String.valueOf(minValue),
                                   String.valueOf(maxValue),
                                   String.valueOf(avgValue)                                
    }; 
    return values;
  }
  
  private String getOwnerNameByActorIDAndActorType(Integer actorID, String actorType, HttpServletRequest request)throws ApplicationException {
    UserRoleDAObject userRoleDAO = new UserRoleDAObject(this.getSessionContainer(request), this.getConnection(request));
    UserGroupDAObject userGroupDAO = new UserGroupDAObject(this.getSessionContainer(request), this.getConnection(request));
    Locale locale = this.getSessionContainer(request).getSessionLocale();
    // Actor Type is User
    if (GlobalConstant.SUBJECT_TYPE_USER.equals(actorType)) {
      return UserInfoFactory.getUserFullName(actorID);
    // Actor Type is Role
    } else if (GlobalConstant.SUBJECT_TYPE_ROLE.equals(actorType)) {
      UserRole userRole = (UserRole)userRoleDAO.getObjectByID(actorID);
      return userRole.getRoleName();
    // Actor Type is Group
    } else if (GlobalConstant.SUBJECT_TYPE_GROUP.equals(actorType)) {
      UserGroup userGroup = (UserGroup)userGroupDAO.getObjectByID(actorID);
      return userGroup.getGroupName();
    } else if (MtmWorkflowStepUserActor.ACTOR_TYPE_EVERYONE.equals(actorType)) {
      String everyOneName = MessageResourcesFactory.getMessage(locale, "workflow.label.everyone");
      return everyOneName;
    } else if (MtmWorkflowStepUserActor.ACTOR_TYPE_SUBMITTER.equals(actorType)) {
    	String submitterName = MessageResourcesFactory.getMessage(locale, "workflow.label.submitter");
      return submitterName;
    } else if (MtmWorkflowStepUserActor.ACTOR_TYPE_REPORT_TO.equals(actorType)) {
    	String reportToName = MessageResourcesFactory.getMessage(locale, "workflow.label.report_to");
      return reportToName;
    } else if (MtmWorkflowStepUserActor.ACTOR_TYPE_PREVIOUS_TASK_ACTION_TAKER.equals(actorType)) {
    	String previousName = MessageResourcesFactory.getMessage(locale, "workflow.label.previous_task_action_taker");
      return previousName;
    } else if (MtmWorkflowStepUserActor.ACTOR_TYPE_REPORT_TO_OF_PREVIOUS_TASK_ACTION_TAKER.equals(actorType)) {
    	String previousToName = MessageResourcesFactory.getMessage(locale, "workflow.label.report_to_of_previous_task");
      return previousToName;
    }
    return null;
  }
}